package com.wlz;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.rpc.Protocol;

import java.util.ServiceLoader;

/**
 * @author wlz
 * @date 2022-07-13  9:14 下午
 */
public class SpiTest {

    public static void main(String[] args) {
        // java spi
//        ServiceLoader<Car> cars = ServiceLoader.load(Car.class);
//        for (Car car : cars) {
//            System.out.println(car.getCarName(null));
//        }

        // dubbo spi
       /* ExtensionLoader<Protocol> extensionLoader = ExtensionLoader.getExtensionLoader(Protocol.class);
        Protocol http = extensionLoader.getExtension("http");
        System.out.println(http);*/


        /*ExtensionLoader<Car> extensionLoader = ExtensionLoader.getExtensionLoader(Car.class);
        Car car = extensionLoader.getExtension("red");// 自动注入 AOP
        System.out.println(car);*/


        // 获取默认的扩展类
       /* ExtensionLoader<Person> extensionLoader = ExtensionLoader.getExtensionLoader(Person.class);
        Person person = extensionLoader.getExtension("true"); // 获取默认的扩展类
        System.out.println(person.getCar());*/


        // 属性赋值
        ExtensionLoader<Person> extensionLoader = ExtensionLoader.getExtensionLoader(Person.class);
        Person person = extensionLoader.getExtension("injectblack");
        System.out.println(" 1:  " + person.getCar());
        URL url = new URL("x", "localhost", 8080);
        url = url.addParameter("car", "black");
        System.out.println(" 2:  " + person.getCar());
        System.out.println(" 3:  " + person.getCar().getCarName(url));

    }
}
